package com.yeming.flink.practice.transformation

import org.apache.flink.streaming.api.scala._

object TranConnectStream {

  def main(args: Array[String]): Unit = {

    //环境设置
    val streamEnv: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    //设置并行度
//    streamEnv.setParallelism(1)
    //添加数据源
    val stream1: DataStream[(String, Int)] = streamEnv.fromElements(("a", 1), ("b", 3))
    val stream2: DataStream[(String)] = streamEnv.fromElements("c","d","e")
    //数据转换
    val stream3: ConnectedStreams[(String, Int), String] = stream1.connect(stream2)

    val result: DataStream[(String, Int)] = stream3.map(
      t => {
        (t._1, t._2 + 10)
      },
      t => {
        (t, 5)
      }
    )

    //数据sink
    result.print()
    //执行数据流
    streamEnv.execute("执行数据流转换")

  }

}
